﻿//========================================================= 
/**@file AndroidLogcatAppender.h
 * @brief 将日志输出到Android平台的Logcat中
 * 
 * @date 2019-03-05   14:32:46
 * @author Zhyioo 
 * @version 1.0
 */ 
//--------------------------------------------------------- 
#ifndef _LIBZHOUYB_ANDROIDLOGCATAPPENDER_H_
#define _LIBZHOUYB_ANDROIDLOGCATAPPENDER_H_
//--------------------------------------------------------- 
#include <android/log.h>

#include "../ILogCat.h"
//--------------------------------------------------------- 
namespace zhou_yb {
namespace extension {
namespace logcat {
//--------------------------------------------------------- 
/**
 * @brief 将日志输出到Android的Logcat中
 * @date 2019-03-05 14:34
 */
class AndroidLogcatAppender : public ILogAppender, public RefObject
{
public:
    virtual void append(LogLevel lv, const char* tag, const char* str)
    {
        int proi = ANDROID_LOG_DEBUG;
        switch(lv)
        {
        case LogAll:
        case LogTrace:
            proi = ANDROID_LOG_VERBOSE;
            break;
        case LogDebug:
            proi = ANDROID_LOG_DEBUG;
            break;
        case LogInfo:
            proi = ANDROID_LOG_INFO;
            break;
        case LogWarning:
            proi = ANDROID_LOG_WARN;
            break;
        case LogError:
            proi = ANDROID_LOG_ERROR;
            break;
        case LogFatal:
            proi = ANDROID_LOG_FATAL;
            break;
        case LogOff:
            break;
        }
        if(_is_empty_or_null(tag))
        {
            tag = "JNI";
        }
        __android_log_write(proi, tag, str);
    }
};
//--------------------------------------------------------- 
} // namespace logcat
} // namespace extension
} // namespace zhou_yb
//--------------------------------------------------------- 
#endif // _LIBZHOUYB_ANDROIDLOGCATAPPENDER_H_
//========================================================= 